﻿
// ———————————————————————–
// <copyright file="IncidentOrganizationTypeGenerator.cs" company="The MITRE Corporation">
//    Copyright (c) 2014 The MITRE Corporation. All rights reserved.
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
//    http://www.apache.org/licenses/LICENSE-2.0
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.
// </copyright>
// ———————————————————————–
/////////////////////////////////////////////////////////////////////////////////////////////////
// IncidentOrganizationTypeGenerator.cs:
//
// A generator for good and bad examples of IncidentOrganizationType.
//
// Project: NIEMCADTest
// Author:  Lizzie DeYoung - MITRE
/////////////////////////////////////////////////////////////////////////////////////////////////

// Copyright (c) 2014 The MITRE Corporation. All rights reserved.
//
// NOTICE
// This software was produced for the U. S. Government
// under Contract No. FA8721-09-C-0001, and is
// subject to the Rights in Noncommercial Computer Software
// and Noncommercial Computer Software Documentation Clause
// (DFARS) 252.227-7014 (JUN 1995)  
      

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using EDXLSharp.NIEMCADLib;
using EDXLSharp.NIEMMilOpsLib;
using EDXLSharp;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Diagnostics;
using System.Reflection;
using NIEMCADTest.NIEMCoreTests;

namespace NIEMCADTest.IncidentDetailTests
{
  public abstract class IncidentOrganizationTypeGenerator : Generator
  {
    public const string ORGANIZATION_ID_SUB = "$organizationId";
    public const string INCIDENT_ID_SUB = "$incidentId";

    public const string INCIDENT_ORGANIZATION_GENERATOR_TYPE = @"
    <$prefix$:$name$ xmlns:$prefix$='$namespace$'>
      $organizationId
      $incidentId
    </$prefix$:$name$>";

    public const string WRONG_ELEMENT_NAME = @"
    <$prefix$:asdf xmlns:$prefix$='$namespace$'>
      $organizationId
      $incidentId
    </$prefix$:asdf>";

    public List<TestObject> BAD_WrongElementName()
    {
      List<TestObject> list = new List<TestObject>();

      // grab good content
      TestObject orgIdTestObject = TestHelper.GetAGoodTestObject(typeof(OrganizationIdentificationGenerator));
      string orgIdXmlText = orgIdTestObject.Xml.OuterXml;
      TestObject resIdTestObject = TestHelper.GetAGoodTestObject(typeof(IncidentIdentifierGenerator));
      string resIdXmlText = resIdTestObject.Xml.OuterXml;

      // add content
      string xml = GetXml(WRONG_ELEMENT_NAME);
      xml = xml.Replace(ORGANIZATION_ID_SUB, orgIdXmlText);
      xml = xml.Replace(INCIDENT_ID_SUB, resIdXmlText);

      TestObject testObject = GetTestObject(xml);

      list.Add(testObject);

      return list;
    }

    public List<TestObject> BAD_MultipleElements()
    {
      List<TestObject> list = new List<TestObject>();
      TestObject testObject;
      string xml;

      // grab good content
      TestObject orgIdTestObject = TestHelper.GetAGoodTestObject(typeof(OrganizationIdentificationGenerator));
      string orgIdXmlText = orgIdTestObject.Xml.OuterXml;
      TestObject resIdTestObject = TestHelper.GetAGoodTestObject(typeof(IncidentIdentifierGenerator));
      string resIdXmlText = resIdTestObject.Xml.OuterXml;

      // add content twice for org
      xml = GetXml(INCIDENT_ORGANIZATION_GENERATOR_TYPE);
      xml = xml.Replace(ORGANIZATION_ID_SUB, orgIdXmlText + orgIdXmlText);
      xml = xml.Replace(INCIDENT_ID_SUB, resIdXmlText);
      testObject = GetTestObject(xml);
      list.Add(testObject);

      // add content twice for res
      xml = GetXml(INCIDENT_ORGANIZATION_GENERATOR_TYPE);
      xml = xml.Replace(ORGANIZATION_ID_SUB, orgIdXmlText);
      xml = xml.Replace(INCIDENT_ID_SUB, resIdXmlText + resIdXmlText);
      testObject = GetTestObject(xml);
      list.Add(testObject);

      return list;
    }

    public List<TestObject> BAD_MissingElements()
    {
      List<TestObject> list = new List<TestObject>();
      TestObject testObject;
      string xml;

      // grab good content
      TestObject orgIdTestObject = TestHelper.GetAGoodTestObject(typeof(OrganizationIdentificationGenerator));
      string orgIdXmlText = orgIdTestObject.Xml.OuterXml;
      TestObject resIdTestObject = TestHelper.GetAGoodTestObject(typeof(IncidentIdentifierGenerator));
      string resIdXmlText = resIdTestObject.Xml.OuterXml;

      // completely empty
      xml = GetXml(INCIDENT_ORGANIZATION_GENERATOR_TYPE);
      xml = xml.Replace(ORGANIZATION_ID_SUB, "");
      xml = xml.Replace(INCIDENT_ID_SUB, "");
      testObject = GetTestObject(xml);
      list.Add(testObject);

      // empty org
      xml = GetXml(INCIDENT_ORGANIZATION_GENERATOR_TYPE);
      xml = xml.Replace(ORGANIZATION_ID_SUB, "");
      xml = xml.Replace(INCIDENT_ID_SUB, resIdXmlText);
      testObject = GetTestObject(xml);
      list.Add(testObject);

      // empty rec
      xml = GetXml(INCIDENT_ORGANIZATION_GENERATOR_TYPE);
      xml = xml.Replace(ORGANIZATION_ID_SUB, orgIdXmlText);
      xml = xml.Replace(INCIDENT_ID_SUB, "");
      testObject = GetTestObject(xml);
      list.Add(testObject);

      return list;
    }

    public List<TestObject> BAD_BadContent()
    {
      // grab good content
      TestObject orgIdTestObject = TestHelper.GetAGoodTestObject(typeof(OrganizationIdentificationGenerator));
      string orgIdXmlText = orgIdTestObject.Xml.OuterXml;
      TestObject incIdTestObject = TestHelper.GetAGoodTestObject(typeof(IncidentIdentifierGenerator));
      string incIdXmlText = incIdTestObject.Xml.OuterXml;

      // get bad lists
      List<TestObject> badOrgIdList = TestHelper.GetBadTestObjects(typeof(OrganizationIdentificationGenerator));
      List<TestObject> badIncIdList = TestHelper.GetBadTestObjects(typeof(IncidentIdentifierGenerator));

      string starterXml = GetXml(INCIDENT_ORGANIZATION_GENERATOR_TYPE);

      // put it all together
      List<TestObject> list = new List<TestObject>();
      foreach (TestObject testObject in badOrgIdList)
      {
        string xml = starterXml;
        xml = xml.Replace(ORGANIZATION_ID_SUB, testObject.Xml.OuterXml);
        xml = xml.Replace(INCIDENT_ID_SUB, incIdXmlText);

        TestObject newTestObject = GetTestObject(xml);
        list.Add(newTestObject);
      }
      foreach (TestObject testObject in badIncIdList)
      {
        string xml = starterXml;
        xml = xml.Replace(ORGANIZATION_ID_SUB, orgIdXmlText);
        xml = xml.Replace(INCIDENT_ID_SUB, testObject.Xml.OuterXml);

        TestObject newTestObject = GetTestObject(xml);
        list.Add(newTestObject);
      }

      return list;
    }

    public List<TestObject> GOOD_GoodContent()
    {
      // grab good lists
      List<TestObject> goodOrgList = TestHelper.GetGoodTestObjects(typeof(OrganizationIdentificationGenerator));
      List<TestObject> goodIncIdList = TestHelper.GetGoodTestObjects(typeof(IncidentIdentifierGenerator));

      List<TestObject> list = new List<TestObject>();
      string starterXml = GetXml(INCIDENT_ORGANIZATION_GENERATOR_TYPE);

      foreach (TestObject orgTestObject in goodOrgList)
      {
        foreach (TestObject incIdTestObject in goodIncIdList)
        {
          string xml = starterXml;
          xml = xml.Replace(ORGANIZATION_ID_SUB, orgTestObject.Xml.OuterXml);
          xml = xml.Replace(INCIDENT_ID_SUB, incIdTestObject.Xml.OuterXml);
          TestObject testObject = GetTestObject(xml);
          list.Add(testObject);
        }
      }
      return list;
    }
  }
}
